const path = require('path');

//在内存中，根据指定的模板页面，生成一份内存中的首页，同时自动把打包好的bundle注入到页面底部
//配置插件需要在导出的对象中，挂载一个plugins节点
const htmlWebpackPlugin = require('html-webpack-plugin');
const VueLoaderPlugin = require('vue-loader/lib/plugin');

module.exports = {
    mode: 'production',
    entry: path.join(__dirname, './src/main.js'),
    output: {
        path: path.join(__dirname, './dist'),
        filename: 'bundle.js'
    },
    plugins: [
        //所有webpack插件的配置节点
        new htmlWebpackPlugin({
            template: path.join(__dirname, './src/index.html'), //指定模板文件路径
            filename: 'index.html' //设置生成页面名称
        }),
        new VueLoaderPlugin()
    ],
    module: {
        rules: [
            { test: /\.css$/, use: ['style-loader', 'css-loader'] },
            { test: /\.less$/, use: ['style-loader', 'css-loader', 'less-loader'] },
            { test: /\.scss$/, use: ['style-loader', 'css-loader', 'sass-loader'] },
            { test: /\.(jpg|png|gif|bmp|jpeg)$/, use: 'url-loader?limit=31444&name=[hash:8]-[name].[ext]' },
            { test: /\.(eot|svg|ttf|woff|woff2)$/, use: 'url-loader' }, //处理字体文件的loader
            { test: /\.js$/, use: 'babel-loader', exclude: /node_modules/ }, //配置Babel来转换高级的ES语法，必须把node_modules目录通过exclude选项排除掉
            { test: /\.vue$/, use: 'vue-loader' } //处理.vue文件
        ]
    },
    performance: { //解决webpack报错WARNING in asset size limit: The following asset(s) exceed the recommended size limit (244 KiB).
        //      This can impact web performance.
        hints: false
    },
    resolve: {
        alias: { //修改vue被导入时的包的路径
            // 'vue$': 'vue/dist/vue.js'
        }
    }
}